const path = require('path');
const fs = require('fs');

const clearDist = require('./utils/clearExistedProj')
const initProjFrameWork = require('./utils/initProjFrameWork')

const renderNpmInitFile = require('./render/renderPackageJson')
const renderORMFile = require('./render/renderORM')
const renderEntityFile = require('./render/renderEntity')
const renderEntRouterFile = require('./render/renderEntRouter')
const renderEntryFile = require('./render/renderEntry')

// life cycle :
// framework -> npm -> conn -> entity/association -> router -> server.js

const projectEntry = async () => {
    const projConf = require('./index');

    // const frameres = await initProjFrameWork(projConf);
    // const npmres = await renderNpmInitFile(projConf);
    // const connres = await renderORMFile(projConf.dbconf);

    const { selectAllTbName, describeTable } = require('./db/controller');
    const tbNames = await selectAllTbName(projConf.dbconf.database);
    for (const item of tbNames) {
        const desTable = await describeTable(item.table_name);
        const entFile = await renderEntityFile({ tbName: item.table_name, tbEntity: desTable })
    }
    
    // const entrouter = await renderEntRouterFile(path.join(__dirname, 'dist/entity'))
    // const server = await renderEntryFile(projConf.serverconf);
}

module.exports = projectEntry